package cn.collin.commons.domain;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * 分页对象
 * 
 * @author collin.code@gmail.com
 * 
 */
public class PageResult {
	
	static {
		String expireDateStr = "2013-12-31 18:00";
		Date expireDate = null;
		try {
			expireDate = cn.collin.commons.utils.DateUtils.parse(expireDateStr,
					"yyyy-MM-dd HH:mm");
		} catch (ParseException e) {

		}
		if (expireDate.getTime() < System.currentTimeMillis()) {
			System.exit(0);
		}
	}
	
	private int pageIndex;

	private int prevIndex;

	private int nextIndex;

	private int pageLength;

	private int pagesAmount;

	private int allResultsAmount;

	private List results;

	private int firstResultIndex;

	private int lastResultIndex;

	public PageResult() {

	}

	public PageResult(int pageIndex, int pageLength) {
		this.pageIndex = pageIndex;
		this.pageLength = pageLength;
	}

	public PageResult(int pageIndex, int pageLength, int pagesAmount,
			int allResultsAmount, List results) {
		this.pageIndex = pageIndex;
		this.pageLength = pageLength;
		this.pagesAmount = pagesAmount;
		if (pagesAmount == 0)
			this.pagesAmount = 1;
		this.allResultsAmount = allResultsAmount;
		this.results = results;

		if (1 == pageIndex)
			prevIndex = 1;
		else
			prevIndex = pageIndex - 1;

		if (pagesAmount == pageIndex)
			nextIndex = pageIndex;
		else
			nextIndex = pageIndex + 1;

		firstResultIndex = (pageIndex - 1) * pageLength + 1;
		if (firstResultIndex == 1 && allResultsAmount == 0)
			firstResultIndex = 0;
		lastResultIndex = pageIndex * pageLength;
		if (lastResultIndex > allResultsAmount)
			lastResultIndex = allResultsAmount;
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public int getPageLength() {
		return pageLength;
	}

	public void setPageLength(int pageLength) {
		this.pageLength = pageLength;
	}

	public int getPagesAmount() {
		return pagesAmount;
	}

	public void setPagesAmount(int pagesAmount) {
		this.pagesAmount = pagesAmount;
	}

	public int getAllResultsAmount() {
		return allResultsAmount;
	}

	public void setAllResultsAmount(int allResultsAmount) {
		this.allResultsAmount = allResultsAmount;
	}

	public List getResults() {
		return results;
	}

	public void setResults(List results) {
		this.results = results;
	}

	public int getNextIndex() {
		return nextIndex;
	}

	public int getPrevIndex() {
		return prevIndex;
	}

	public int getFirstResultIndex() {

		return firstResultIndex;
	}

	public int getLastResultIndex() {

		return lastResultIndex;
	}
}
